
<?php
include('../../../dbconfig.php');

$per_page = 12;

if($_GET)
{
	$page=$_GET['page'];
}


//get table contents
$start = ($page-1)*$per_page;
$sql = "SELECT * FROM album ORDER BY album_id limit $start,$per_page";
$rsd = mysql_query($sql);
$length = 0;
$numOfRow = mysql_num_rows($rsd)-1;
while($row = mysql_fetch_array($rsd))
{
	$src= "../../../images/uploads/".$row['album_id']."_".$row['album_name']."/";
	$date = $row['inserted_date_time'];
	$dirname =  iconv("UTF-8","windows-874",$src);
	$path = "";
	$count = 0;
	if((($files = @scandir($dirname)) && !count($files) <= 2))
	{
		$images = scandir($dirname);
		$ignore = Array(".", "..","", "otherfiletoignore");
		$imgname = "";	
		foreach($images as $curimg){			
			if(!in_array($curimg, $ignore)) {				
				if($count==0)
					$imgname = $curimg;
				$count++;
			}
		}
		$path = str_replace("../../","",$src.$imgname);	
	}
	
	if($path == ""){
		$path = "../images/uploads/no_image.jpg";
	}
	
	if($length == 0){
		echo "<tr valign=\"top\">
				<td>
					<a href=\"#\" onClick=\"delete_album('".$row['album_id']."','".$row['album_name']."')\" ><div class=\"BtnGalleryDelete\"></div></a>
					<a href=\"#\" onClick=\"gallery_albumEdit_Onclick('".$row['album_id']."','".$row['album_name']."','".$row['album_description']."','".$row['album_photographer']."')\" ><div class=\"BtnEditImg\"></div></a>
					<a href=\"#\" onClick=\"gallery_imgManage_Onclick('".$row['album_id']."_".$row['album_name']."')\"><img src=\"$path\" width=\"120\" height=\"100\" /></a>
					<div id=\"album_name\"><a href=\"#\">".$row['album_name']."</a></div>
					<div class=\"pic_count\">จำนวนรูป : $count รูป <br/>ผู้ลง : ".$row['inserted_master_id']."<br/>ผู้ถ่าย : ".$row['album_photographer']."<br/> 
					แก้ไขล่าสุด : ".substr($date, 6,2)."/".substr($date, 4,2)."/".substr($date, 0,4).",".substr($date, 8,2).":".substr($date, 10,2)."<br />
					</div>
				</td>";
		if($length == $numOfRow) echo "</tr>";
	}else if($length % 4 > 0 && $length % 4 < 4){
		echo "	<td>
					<a href=\"#\" onClick=\"delete_album('".$row['album_id']."','".$row['album_name']."')\" ><div class=\"BtnGalleryDelete\"></div></a>
					<a href=\"#\" onClick=\"gallery_albumEdit_Onclick('".$row['album_id']."','".$row['album_name']."','".$row['album_description']."','".$row['album_photographer']."')\" ><div class=\"BtnEditImg\"></div></a>
					<a href=\"#\" onClick=\"gallery_imgManage_Onclick('".$row['album_id']."_".$row['album_name']."')\"><img src=\"$path\" width=\"120\" height=\"100\" /></a>
					<div id=\"album_name\"><a href=\"#\">".$row['album_name']."</a></div>
					<div class=\"pic_count\">จำนวนรูป : $count รูป <br/>ผู้ลง : ".$row['inserted_master_id']."<br/>ผู้ถ่าย : ".$row['album_photographer']."<br/> 
					แก้ไขล่าสุด : ".substr($date, 6,2)."/".substr($date, 4,2)."/".substr($date, 0,4).",".substr($date, 8,2).":".substr($date, 10,2)."<br />
					</div>
				 </td>";
		if($length == $numOfRow) echo "</tr></table>";
	}else if($length % 4 == 0){
		echo "<tr valign=\"top\">
				<td>
					<a href=\"#\" onClick=\"delete_album('".$row['album_id']."','".$row['album_name']."')\" ><div class=\"BtnGalleryDelete\"></div></a>
					<a href=\"#\" onClick=\"gallery_albumEdit_Onclick('".$row['album_id']."','".$row['album_name']."','".$row['album_description']."','".$row['album_photographer']."')\" ><div class=\"BtnEditImg\"></div></a>
					<a href=\"#\" onClick=\"gallery_imgManage_Onclick('".$row['album_id']."_".$row['album_name']."')\"><img src=\"$path\" width=\"120\" height=\"100\" /></a>
					<div id=\"album_name\"><a href=\"#\">".$row['album_name']."</a></div>
					<div class=\"pic_count\">จำนวนรูป : $count รูป <br/>ผู้ลง : ".$row['inserted_master_id']."<br/>ผู้ถ่าย : ".$row['album_photographer']."<br/> 
					แก้ไขล่าสุด : ".substr($date, 6,2)."/".substr($date, 4,2)."/".substr($date, 0,4).",".substr($date, 8,2).":".substr($date, 10,2)."<br />
					</div>
				 </td>";
		if($length == $numOfRow) echo "</tr></table>";
	}
	$length++;
	$path="";
}

?>
